home *** CD-ROM | disk | FTP | other *** search
/ Ultra Pack / UltraComputing Partner Applications.iso / SunLabs / tclTK / src / tk4.0 / tests / canvImg.test < prev    next >
Encoding:
Text File  |  1995-03-11  |  12.3 KB  |  400 lines

  1. # This file is a Tcl script to test out the procedures in tkCanvImg.c,
  2. # which implement canvas "image" items.  It is organized in the standard
  3. # fashion for Tcl tests.
  4. #
  5. # Copyright (c) 1994 The Regents of the University of California.
  6. # Copyright (c) 1994 Sun Microsystems, Inc.
  7. #
  8. # See the file "license.terms" for information on usage and redistribution
  9. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  10. #
  11. # @(#) canvImg.test 1.7 95/03/10 16:49:08
  12.  
  13. if {[lsearch [image types] test] < 0} {
  14.     puts "This application hasn't been compiled with the \"test\" image"
  15.     puts "type, so I can't run this test.  Are you sure you're using"
  16.     puts "tktest instead of wish?"
  17.     return
  18. }
  19.  
  20. if {[info procs test] != "test"} {
  21.     source defs
  22. }
  23.  
  24. foreach i [winfo children .] {
  25.     destroy $i
  26. }
  27. wm geometry . {}
  28. raise .
  29.  
  30. eval image delete [image names]
  31. canvas .c
  32. pack .c
  33. update
  34. image create test foo -variable x
  35. image create test foo2 -variable y
  36. foo2 changed 0 0 0 0 80 60
  37. test canvImg-1.1 {options for image items} {
  38.     .c delete all
  39.     .c create image 50 50 -anchor nw -tags i1
  40.     .c itemconfigure i1 -anchor
  41. } {-anchor {} {} center nw}
  42. test canvImg-1.2 {options for image items} {
  43.     .c delete all
  44.     list [catch {.c create image 50 50 -anchor gorp -tags i1} msg] $msg
  45. } {1 {bad anchor position "gorp": must be n, ne, e, se, s, sw, w, nw, or center}}
  46. test canvImg-1.3 {options for image items} {
  47.     .c delete all
  48.     .c create image 50 50 -image foo -tags i1
  49.     .c itemconfigure i1 -image
  50. } {-image {} {} {} foo}
  51. test canvImg-1.4 {options for image items} {
  52.     .c delete all
  53.     list [catch {.c create image 50 50 -image unknown -tags i1} msg] $msg
  54. } {1 {image "unknown" doesn't exist}}
  55. test canvImg-1.5 {options for image items} {
  56.     .c delete all
  57.     .c create image 50 50 -image foo -tags {i1 foo}
  58.     .c itemconfigure i1 -tags
  59. } {-tags {} {} {} {i1 foo}}
  60.  
  61. test canvImg-2.1 {CreateImage procedure} {
  62.     list [catch {.c create image 40} msg] $msg
  63. } {1 {wrong # args:  should be ".c create image x y ?options?"}}
  64. test canvImg-2.2 {CreateImage procedure} {
  65.     list [catch {.c create image 40 50 60} msg] $msg
  66. } {1 {unknown option "60"}}
  67. test canvImg-2.3 {CreateImage procedure} {
  68.     .c delete all
  69.     set i [.c create image 50 50]
  70.     list [lindex [.c itemconf $i -anchor] 4] \
  71.         [lindex [.c itemconf $i -image] 4] \
  72.         [lindex [.c itemconf $i -tags] 4]
  73. } {center {} {}}
  74. test canvImg-2.4 {CreateImage procedure} {
  75.     list [catch {.c create image xyz 40} msg] $msg
  76. } {1 {bad screen distance "xyz"}}
  77. test canvImg-2.5 {CreateImage procedure} {
  78.     list [catch {.c create image 50 qrs} msg] $msg
  79. } {1 {bad screen distance "qrs"}}
  80. test canvImg-2.6 {CreateImage procedure} {
  81.     list [catch {.c create image 50 50 -gorp foo} msg] $msg
  82. } {1 {unknown option "-gorp"}}
  83.  
  84. test canvImg-3.1 {ImageCoords procedure} {
  85.     .c delete all
  86.     .c create image 50 100 -image foo -tags i1
  87.     .c coords i1
  88. } {50.0 100.0}
  89. test canvImg-3.2 {ImageCoords procedure} {
  90.     .c delete all
  91.     .c create image 50 100 -image foo -tags i1
  92.     list [catch {.c coords i1 dumb 100} msg] $msg
  93. } {1 {bad screen distance "dumb"}}
  94. test canvImg-3.3 {ImageCoords procedure} {
  95.     .c delete all
  96.     .c create image 50 100 -image foo -tags i1
  97.     list [catch {.c coords i1 250 dumb0} msg] $msg
  98. } {1 {bad screen distance "dumb0"}}
  99. test canvImg-3.4 {ImageCoords procedure} {
  100.     .c delete all
  101.     .c create image 50 100 -image foo -tags i1
  102.     list [catch {.c coords i1 250} msg] $msg
  103. } {1 {wrong # coordinates:  expected 0 or 2, got 1}}
  104. test canvImg-3.5 {ImageCoords procedure} {
  105.     .c delete all
  106.     .c create image 50 100 -image foo -tags i1
  107.     list [catch {.c coords i1 250 300 400} msg] $msg
  108. } {1 {wrong # coordinates:  expected 0 or 2, got 3}}
  109.  
  110. test canvImg-4.1 {ConfiugreImage procedure} {
  111.     .c delete all
  112.     .c create image 50 100 -image foo -tags i1
  113.     update
  114.     set x {}
  115.     .c itemconfigure i1 -image {}
  116.     update
  117.     list $x [.c bbox i1]
  118. } {{{foo free}} {50 100 50 100}}
  119. test canvImg-4.2 {ConfiugreImage procedure} {
  120.     .c delete all
  121.     .c create image 50 100 -image foo -tags i1 -anchor nw
  122.     update
  123.     set x {}
  124.     set y {}
  125.     .c itemconfigure i1 -image foo2
  126.     update
  127.     list $x $y [.c bbox i1]
  128. } {{{foo free}} {{foo2 get} {foo2 display 0 0 80 60 30 30}} {50 100 130 160}}
  129. test canvImg-4.3 {ConfiugreImage procedure} {
  130.     .c delete all
  131.     .c create image 50 100 -image foo -tags i1 -anchor nw
  132.     update
  133.     set x {}
  134.     set y {}
  135.     list [catch {.c itemconfigure i1 -image lousy} msg] $msg
  136. } {1 {image "lousy" doesn't exist}}
  137.  
  138. test canvImg-5.1 {DeleteImage procedure} {
  139.     image create test xyzzy -variable z
  140.     .c delete all
  141.     .c create image 50 100 -image xyzzy -tags i1
  142.     update
  143.     image delete xyzzy
  144.     set z {}
  145.     set names [lsort [image names]]
  146.     .c delete i1
  147.     update
  148.     list $names $z [lsort [image names]]
  149. } {{foo foo2 xyzzy} {} {foo foo2}}
  150. test canvImg-5.2 {DeleteImage procedure (don't delete non-existent image)} {
  151.     .c delete all
  152.     .c create image 50 100 -tags i1
  153.     update
  154.     .c delete i1
  155.     update
  156. } {}
  157.  
  158. test canvImg-6.1 {ComputeImageBbox procedure} {
  159.     .c delete all
  160.     .c create image 15.51 17.51 -image foo -tags i1 -anchor nw
  161.     .c bbox i1
  162. } {16 18 46 33}
  163. test canvImg-6.2 {ComputeImageBbox procedure} {
  164.     .c delete all
  165.     .c create image 15.49 17.49 -image foo -tags i1 -anchor nw
  166.     .c bbox i1
  167. } {15 17 45 32}
  168. test canvImg-6.3 {ComputeImageBbox procedure} {
  169.     .c delete all
  170.     .c create image 20 30 -tags i1 -anchor nw
  171.     .c bbox i1
  172. } {20 30 20 30}
  173. test canvImg-6.4 {ComputeImageBbox procedure} {
  174.     .c delete all
  175.     .c create image 20 30 -image foo -tags i1 -anchor nw
  176.     .c bbox i1
  177. } {20 30 50 45}
  178. test canvImg-6.5 {ComputeImageBbox procedure} {
  179.     .c delete all
  180.     .c create image 20 30 -image foo -tags i1 -anchor n
  181.     .c bbox i1
  182. } {5 30 35 45}
  183. test canvImg-6.6 {ComputeImageBbox procedure} {
  184.     .c delete all
  185.     .c create image 20 30 -image foo -tags i1 -anchor ne
  186.     .c bbox i1
  187. } {-10 30 20 45}
  188. test canvImg-6.7 {ComputeImageBbox procedure} {
  189.     .c delete all
  190.     .c create image 20 30 -image foo -tags i1 -anchor e
  191.     .c bbox i1
  192. } {-10 23 20 38}
  193. test canvImg-6.8 {ComputeImageBbox procedure} {
  194.     .c delete all
  195.     .c create image 20 30 -image foo -tags i1 -anchor se
  196.     .c bbox i1
  197. } {-10 15 20 30}
  198. test canvImg-6.9 {ComputeImageBbox procedure} {
  199.     .c delete all
  200.     .c create image 20 30 -image foo -tags i1 -anchor s
  201.     .c bbox i1
  202. } {5 15 35 30}
  203. test canvImg-6.10 {ComputeImageBbox procedure} {
  204.     .c delete all
  205.     .c create image 20 30 -image foo -tags i1 -anchor sw
  206.     .c bbox i1
  207. } {20 15 50 30}
  208. test canvImg-6.11 {ComputeImageBbox procedure} {
  209.     .c delete all
  210.     .c create image 20 30 -image foo -tags i1 -anchor w
  211.     .c bbox i1
  212. } {20 23 50 38}
  213. test canvImg-6.12 {ComputeImageBbox procedure} {
  214.     .c delete all
  215.     .c create image 20 30 -image foo -tags i1 -anchor center
  216.     .c bbox i1
  217. } {5 23 35 38}
  218.  
  219. # The followin test is non-portable because of differences in
  220. # coordinate rounding on some machines (does 0.5 round  up?).
  221.  
  222. if $doNonPortableTests {
  223.     test canvImg-7.1 {DisplayImage procedure} {
  224.     .c delete all
  225.     .c create image 50 100 -image foo -tags i1 -anchor nw
  226.     update
  227.     set x {}
  228.     .c create rect 55 110 65 115 -width 1 -outline black -fill white
  229.     update
  230.     set x
  231.     } {{foo display 4 9 13 6 30 30}}
  232. }
  233. test canvImg-7.2 {DisplayImage procedure, no image} {
  234.     .c delete all
  235.     .c create image 50 100 -tags i1
  236.     update
  237.     .c create rect 55 110 65 115 -width 1 -outline black -fill white
  238.     update
  239. } {}
  240.  
  241. set i 1
  242. .c delete all
  243. .c create image 50 100 -image foo -tags image -anchor nw
  244. .c create rect 10 10 20 20 -tags rect -fill black -width 0 -outline {}
  245. foreach check {
  246.     {{50 70 80 81} {70 90} {rect}}
  247.     {{50 70 80 79} {70 90} {image}}
  248.     {{99 70 110 81} {90 90} {rect}}
  249.     {{101 70 110 79} {90 90} {image}}
  250.     {{99 100 110 115} {90 110} {rect}}
  251.     {{101 100 110 115} {90 110} {image}}
  252.     {{99 134 110 145} {90 125} {rect}}
  253.     {{101 136 110 145} {90 125} {image}}
  254.     {{50 134 80 145} {70 125} {rect}}
  255.     {{50 136 80 145} {70 125} {image}}
  256.     {{20 134 31 145} {40 125} {rect}}
  257.     {{20 136 29 145} {40 125} {image}}
  258.     {{20 100 31 115} {40 110} {rect}}
  259.     {{20 100 29 115} {40 110} {image}}
  260.     {{20 70 31 80} {40 90} {rect}}
  261.     {{20 70 29 79} {40 90} {image}}
  262.     {{60 70 69 109} {70 110} {image}}
  263.     {{60 70 71 111} {70 110} {rect}}
  264. } {
  265.     test canvImg-8.$i {ImageToPoint procedure} {
  266.     eval .c coords rect [lindex $check 0]
  267.     .c gettags [eval .c find closest [lindex $check 1]]
  268.     } [lindex $check 2]
  269.     incr i
  270. }
  271.  
  272. .c delete all
  273. .c create image 50 100 -image foo -tags image -anchor nw
  274. test canvImg-8.1 {ImageToArea procedure} {
  275.     .c gettags [.c find overlapping 60 0 70 99]
  276. } {}
  277. test canvImg-8.2 {ImageToArea procedure} {
  278.     .c gettags [.c find overlapping 60 0 70 99.999]
  279. } {}
  280. test canvImg-8.3 {ImageToArea procedure} {
  281.     .c gettags [.c find overlapping 60 0 70 101]
  282. } {image}
  283. test canvImg-8.4 {ImageToArea procedure} {
  284.     .c gettags [.c find overlapping 81 105 120 115]
  285. } {}
  286. test canvImg-8.5 {ImageToArea procedure} {
  287.     .c gettags [.c find overlapping 80.001 105 120 115]
  288. } {}
  289. test canvImg-8.6 {ImageToArea procedure} {
  290.     .c gettags [.c find overlapping 79 105 120 115]
  291. } {image}
  292. test canvImg-8.7 {ImageToArea procedure} {
  293.     .c gettags [.c find overlapping 60 116 70 150]
  294. } {}
  295. test canvImg-8.8 {ImageToArea procedure} {
  296.     .c gettags [.c find overlapping 60 115.001 70 150]
  297. } {}
  298. test canvImg-8.9 {ImageToArea procedure} {
  299.     .c gettags [.c find overlapping 60 114 70 150]
  300. } {image}
  301. test canvImg-8.10 {ImageToArea procedure} {
  302.     .c gettags [.c find overlapping 0 105 49 115]
  303. } {}
  304. test canvImg-8.11 {ImageToArea procedure} {
  305.     .c gettags [.c find overlapping 0 105 50 114.999]
  306. } {}
  307. test canvImg-8.12 {ImageToArea procedure} {
  308.     .c gettags [.c find overlapping 0 105 51 115]
  309. } {image}
  310. test canvImg-8.13 {ImageToArea procedure} {
  311.     .c gettags [.c find overlapping 0 0 49.999 99.999]
  312. } {}
  313. test canvImg-8.14 {ImageToArea procedure} {
  314.     .c gettags [.c find overlapping 0 0 51 101]
  315. } {image}
  316. test canvImg-8.15 {ImageToArea procedure} {
  317.     .c gettags [.c find overlapping 80 0 150 100]
  318. } {}
  319. test canvImg-8.16 {ImageToArea procedure} {
  320.     .c gettags [.c find overlapping 79 0 150 101]
  321. } {image}
  322. test canvImg-8.17 {ImageToArea procedure} {
  323.     .c gettags [.c find overlapping 80.001 115.001 150 180]
  324. } {}
  325. test canvImg-8.18 {ImageToArea procedure} {
  326.     .c gettags [.c find overlapping 79 114 150 180]
  327. } {image}
  328. test canvImg-8.19 {ImageToArea procedure} {
  329.     .c gettags [.c find overlapping 0 115 50 180]
  330. } {}
  331. test canvImg-8.20 {ImageToArea procedure} {
  332.     .c gettags [.c find overlapping 0 114 51 180]
  333. } {image}
  334. test canvImg-8.21 {ImageToArea procedure} {
  335.     .c gettags [.c find enclosed 0 0 200 200]
  336. } {image}
  337. test canvImg-8.22 {ImageToArea procedure} {
  338.     .c gettags [.c find enclosed 49.999 99.999 80.001 115.001]
  339. } {image}
  340. test canvImg-8.23 {ImageToArea procedure} {
  341.     .c gettags [.c find enclosed 51 100 80 115]
  342. } {}
  343. test canvImg-8.24 {ImageToArea procedure} {
  344.     .c gettags [.c find enclosed 50 101 80 115]
  345. } {}
  346. test canvImg-8.25 {ImageToArea procedure} {
  347.     .c gettags [.c find enclosed 50 100 79 115]
  348. } {}
  349. test canvImg-8.26 {ImageToArea procedure} {
  350.     .c gettags [.c find enclosed 50 100 80 114]
  351. } {}
  352.  
  353. test canvImg-9.1 {DisplayImage procedure} {
  354.     .c delete all
  355.     .c create image 50 100 -image foo -tags image -anchor nw
  356.     .c scale image 25 0 2.0 1.5
  357.     .c bbox image
  358. } {75 150 105 165}
  359.  
  360. test canvImg-10.1 {TranslateImage procedure} {
  361.     .c delete all
  362.     .c create image 50 100 -image foo -tags image -anchor nw
  363.     update
  364.     set x {}
  365.     foo changed 2 4 6 8 30 15
  366.     update
  367.     set x
  368. } {{foo display 2 4 6 8 30 30}}
  369.  
  370. test canvImg-11.1 {TranslateImage procedure} {
  371.     .c delete all
  372.     .c create image 50 100 -image foo -tags image -anchor nw
  373.     update
  374.     set x {}
  375.     foo changed 2 4 6 8 40 50
  376.     update
  377.     set x
  378. } {{foo display 0 0 40 50 30 30}}
  379. test canvImg-11.2 {ImageChangedProc procedure} {
  380.     .c delete all
  381.     image create test foo -variable x
  382.     .c create image 50 100 -image foo -tags image -anchor center
  383.     update
  384.     set x {}
  385.     foo changed 0 0 0 0 40 50
  386.     .c bbox image
  387. } {30 75 70 125}
  388. test canvImg-11.3 {ImageChangedProc procedure} {
  389.     .c delete all
  390.     image create test foo -variable x
  391.     foo changed 0 0 0 0 40 50
  392.     .c create image 50 100 -image foo -tags image -anchor nw
  393.     .c create image 70 110 -image foo2 -anchor nw
  394.     update
  395.     set y {}
  396.     image create test foo -variable x
  397.     update
  398.     set y
  399. } {{foo2 display 0 0 20 40 50 40}}
  400.